package cn.joker.feign.fallback;

import cn.joker.feign.RedisFeignClient;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RedisFeignClientFallbackFactory implements FallbackFactory<RedisFeignClient> {

    @Override
    public RedisFeignClient create(Throwable cause) {
        System.err.println("==== fallbackFactory 被调用 ====");
        return new RedisFeignClient() {
            @Override
            public String set() {
                System.err.println("调用 RedisFeignClient.set 失败，原因: " + cause.getMessage());
                return "fallback: set方法失败";
            }

            @Override
            public Object get() {
                System.err.println("调用 RedisFeignClient.get 失败，原因: " + cause.getMessage());
                return "fallback: get方法失败";
            }
        };
    }
}
